from django.contrib.auth.hashers import make_password
from rest_framework import serializers

from apps.users.models import User




class UserCreateSerialzier(serializers.ModelSerializer):
    class Meta:
        model  = User
        fields = ('id','username','mobile','email','password')
        extra_kwargs = {
            'password': {'write_only': True}}


    def create(self, validated_data):
        user = super().create(validated_data)
        user.set_password(validated_data.get('password'))
        user.save()
        return user
        #
        # validated_data['password'] =make_password(validated_data.get('password'))
        # user= User.objects.create_user(**validated_data)
        # return user

class UUUUUU(serializers.ModelSerializer):
    class Meta:
        model =  User
        fields = ('id','mobile','username','password','email')
        extra_kwargs = {
            'password':{'write_only':True}
        }
    def create(self, validated_data):
        user=  super().create(validated_data)
        user.set_password(validated_data.get('password'))
        user.save()
        return user

